package com.sunnay.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunnay.entity.AppUserOrderEntity;
import com.sunnay.mapper.AppUserOrderMapper;
import com.sunnay.service.AppUserOrderService;
import com.sunnay.util.CommUtils;
import com.sunnay.vo.auth.SystemUser;
import com.sunnay.vo.common.Page;
import com.sunnay.vo.order.QueryOrderVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class AppUserOrderServiceImpl extends ServiceImpl<AppUserOrderMapper, AppUserOrderEntity> implements AppUserOrderService {
    @Override
    public List<AppUserOrderEntity> orderList(SystemUser systemUser, QueryOrderVo orderVo, Page page) {
        List<AppUserOrderEntity> appUserOrderEntities = this.baseMapper.orderList(systemUser.getWxId(), orderVo, page);
        Optional.ofNullable(appUserOrderEntities).ifPresent(item->{
            item.forEach(data->{
                data.setAliUrl(String.format(CommUtils.ALI_URL,data.getPayUri().replaceAll("https://w.weipaitang.com/payOrder/friend","").replaceAll("\\?r=buyerOrder&c=buyerOrder","")));
            });
        });
        return appUserOrderEntities;
    }
}
